package Controller;



import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.nimbus.NimbusLookAndFeel;

import View.LoginPanel;

public class MainFrame extends JFrame implements ActionListener{
	String[] str1 = { "学号：", "姓名：", "班级：", "专业：", "出生年月：" };
	String[] str2 = { "查询", "添加", "删除", "修改" };
	JTextField[] textField=new JTextField[str1.length];
	JLabel[] lable=new JLabel[str1.length];
	JButton[] button=new JButton[str2 .length];
	private static final long serialVersionUID = 1L;
Font font =new Font("微软雅黑", Font.TRUETYPE_FONT, 20);
	public MainFrame() {
		setTitle("学生窗口");
		setVisible(true);
		setSize(600,500);
		setLocationRelativeTo(null);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setLayout(new BorderLayout());
	

		
		JPanel jpanel1=new JPanel();
		jpanel1.setLayout(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();
		for (int i = 0; i < str1.length; i++) {
			lable[i]=new  JLabel(str1[i]);
			lable[i].setFont(font);
			gbc.gridx = 0 ;
			gbc.gridy = i ;
			gbc.insets = new Insets(10, 10, 10, 10);
			jpanel1.add(lable[i],gbc);
			textField[i]=new JTextField(20);
			textField[i].setFont(font);
			gbc.gridx = 1 ;
			gbc.gridy = i ;
			
			gbc.insets = new Insets(10, 10, 10, 10);
			jpanel1.add(textField[i],gbc);
			
		}
		JPanel jpanel2=new JPanel();
		jpanel2.setLayout(new FlowLayout());
		
		for (int i = 0; i < button.length; i++) {
			button[i]=new JButton(str2[i]);
			button[i].setFont(font);
			
			 jpanel2.add(button[i]);
		}
			add(jpanel1);
			add(jpanel2 ,BorderLayout.SOUTH);
			LoginPanel loginPanel=new LoginPanel();
			setGlassPane(loginPanel);
			loginPanel.setVisible(true);
	}

	public static void main(String[] args) {

		SwingUtilities.invokeLater(new Runnable() {
			
			@Override
			public void run() {
				try {
					UIManager.setLookAndFeel(new NimbusLookAndFeel());
				} catch (UnsupportedLookAndFeelException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				new MainFrame();
			}
		});
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (textField[0].equals(" ")||textField[0].getText().startsWith(" ")) {
			JOptionPane.showMessageDialog(null,"学号不能为空", 
					"警告",JOptionPane.WARNING_MESSAGE);
			return;
			
		}
		
	}

	private void handle() {
		
	}
}
